﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SuiYuan.UI.Controls.NaviMenu
{
    /// <summary>
    /// LayUIMenu.xaml 的交互逻辑
    /// </summary>
    public partial class LayUIMenu : UserControl
    {
        public LayUIMenu()
        {
            InitializeComponent();
        }

        private IEnumerable itemSource;
        public IEnumerable ItemsSource
        {
            get
            {
                return itemSource;
            }
            set
            {
                this.itemSource = value;
                itemControl.ItemsSource = value;
            }
        }

        //第一步：声明并注册【路由事件】
        public static readonly RoutedEvent OpenEvent = EventManager.RegisterRoutedEvent("ItemClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(LayUIMenu));

        //第二步：为路由事件添加CLR事件包装器
        public event RoutedEventHandler ItemClick
        {
            add { this.AddHandler(OpenEvent, value); }
            remove { this.RemoveHandler(OpenEvent, value); }
        }
        //分发事件
        private void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            RadioButton button = sender as RadioButton;
            //创建事件携带信息（RoutedEventArgs类实例）,并和路由事件关联
            RoutedEventArgs args = new RoutedEventArgs(OpenEvent, button.Content);
            //调用元素的RaiseEvent方法（继承自UIElement类），将事件发出去
            this.RaiseEvent(args);
        }
    }
}
